//
//  BettingCell.m
//  WangLottery
//
//  Created by 黄修勇 on 12-4-24.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "BettingCell.h"

@implementation BettingCell

@synthesize lotteryTypeImageView=_lotteryTypeImageView;
@synthesize titleLable=_titleLable;
@synthesize periodLabel=_periodLabel;
@synthesize mostMoneyText=_mostMoneyText;
@synthesize isTodayLottery=_isTodayLottery;
@synthesize upDateLabel=_upDateLabel;
@synthesize isShowMoneyLabel=_isShowMoneyLabel;

-(void)dealloc{

    [_lotteryTypeImageView release];
    [_titleLable release];
    [_periodLabel release];
    [_mostMoneyText release];
    [moneyLabel release];
    [moneyAfterLabel release];
    [moneyBeforLabel release];
    [isTodayLotteryLabel release];
    [_upDateLabel release];
    [super dealloc];
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        
        if (!_lotteryTypeImageView) {
            UIImageView *imgView=[[UIImageView alloc]initWithImage:nil];
            imgView.backgroundColor=[UIColor clearColor];
            self.lotteryTypeImageView=imgView;
            [imgView release];
        }
        
        if (!_titleLable) {
            UILabel *titleLabel=[[UILabel alloc]initWithFrame:CGRectMake(70.0f, 3.0f, 70.0f, 20.0f)];
            titleLabel.backgroundColor=[UIColor clearColor];
            titleLabel.textColor=[UIColor blackColor];
            self.titleLable=titleLabel;
            [titleLabel release];
        }
        
        if (!_periodLabel) {
            UILabel *periodLabel=[UILabel creatBettingCellLabelWithFrame:CGRectMake(150.0f, 5.0f, 10.0f, 10.0f)];
            periodLabel.text=@"第2012001期";
            [periodLabel sizeToFit];
            self.periodLabel=periodLabel;
            [periodLabel release];
        }
        isTodayLotteryLabel=[UILabel creatBettingCellLabelWithFrame:CGRectMake(_periodLabel.frame.origin.x+_periodLabel.frame.size.width-10.0f, _periodLabel.frame.origin.y, 10.0f, 10.0f)];
        isTodayLotteryLabel.textColor=[UIColor redColor];
        isTodayLotteryLabel.text=@"(今日开奖)";
        [isTodayLotteryLabel sizeToFit];
        isTodayLotteryLabel.hidden=YES;
        [self.contentView addSubview:isTodayLotteryLabel];
        
        moneyBeforLabel=[UILabel creatBettingCellLabelWithFrame:CGRectMake(70.0f, 22.0f, 10.0f, 10.0f)];
        moneyBeforLabel.text=@"单注最高奖金";
        [moneyBeforLabel sizeToFit];
        [self.contentView addSubview:moneyBeforLabel];
        
        moneyLabel=[UILabel creatBettingCellLabelWithFrame:CGRectMake(moneyBeforLabel.frame.origin.x+moneyBeforLabel.frame.size.width, moneyBeforLabel.frame.origin.y, 10.0f, 10.0f)];
        moneyLabel.text=@"1000万";
        moneyLabel.textColor=[UIColor redColor];
        [moneyLabel sizeToFit];
        [self.contentView addSubview:moneyLabel];
        
        moneyAfterLabel=[UILabel creatBettingCellLabelWithFrame:CGRectMake(moneyLabel.frame.origin.x+moneyLabel.frame.size.width, moneyLabel.frame.origin.y, 10.0f, 10.0f)];
        moneyAfterLabel.text=@"元";
        [moneyAfterLabel sizeToFit];
        [self.contentView addSubview:moneyAfterLabel];
        
        if (!_upDateLabel) {
            UILabel *updateLabel=[UILabel creatBettingCellLabelWithFrame:CGRectMake(70.0f, 40.0f, 180.0f, 15.0f)];
            self.upDateLabel=updateLabel;
            [updateLabel release];
        }
    }
    return self;
}

-(void)setIsShowMoneyLabel:(BOOL)isShowMoneyLabel{

    moneyBeforLabel.hidden=!isShowMoneyLabel;
    moneyAfterLabel.hidden=!isShowMoneyLabel;
}

-(void)setLotteryTypeImageView:(UIImageView *)lotteryTypeImageView{

    if ([_lotteryTypeImageView isEqual:lotteryTypeImageView]) {
        return;
    }
    [_lotteryTypeImageView removeFromSuperview];
    [_lotteryTypeImageView release];
    _lotteryTypeImageView=[lotteryTypeImageView retain];
    _lotteryTypeImageView.frame=CGRectMake(10.0f, 5.0f, 60.0f-10.0f, 60.0f-10.0f);
    [self.contentView addSubview:_lotteryTypeImageView];
}

-(void)setTitleLable:(UILabel *)titleLable{

    if ([titleLable isEqual:_titleLable]) {
        return;
    }
    [_titleLable release];
    [_titleLable removeFromSuperview];
    _titleLable=[titleLable retain];
    [self.contentView addSubview:_titleLable];
}

-(void)setPeriodLabel:(UILabel *)periodLabel{

    if ([periodLabel isEqual:_periodLabel]) {
        return;
    }
    [_periodLabel removeFromSuperview];
    [_periodLabel release];
    _periodLabel=[periodLabel retain];
    [self.contentView addSubview:_periodLabel];
}

-(void)setMostMoneyText:(NSString *)mostMoneyText{

    moneyLabel.text=mostMoneyText;
}

-(NSString *)mostMoneyText{

    return moneyLabel.text;
}

-(void)setIsTodayLottery:(BOOL)isTodayLottery{

    if (isTodayLottery==self.isTodayLottery) {
        return;
    }
    _isTodayLottery=isTodayLottery;
    isTodayLotteryLabel.hidden=!isTodayLottery;
}

-(void)setUpDateLabel:(UILabel *)upDateLabel{

    if ([upDateLabel isEqual:_upDateLabel]) {
        return;
    }
    [_upDateLabel removeFromSuperview];
    [_upDateLabel release];
    _upDateLabel=[upDateLabel retain];
    [self.contentView addSubview:_upDateLabel];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    [self setLabelSelect:selected];
    // Configure the view for the selected state
}

-(void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated{

    [super setHighlighted:highlighted animated:animated];
    [self setLabelSelect:highlighted];
}
-(void)setLabelSelect:(BOOL)isSelect{

    if (isSelect) {
        for (UIView *view in self.contentView.subviews) {
            if ([view isKindOfClass:[UILabel class]]) {
                [(UILabel *)view setTextColor:[UIColor whiteColor]];
            }
        }
    }else {
        UIColor *black=[UIColor blackColor];
        UIColor *redColor=[UIColor redColor];
        
        _titleLable.textColor=black;
        moneyLabel.textColor=redColor;
        moneyBeforLabel.textColor=black;
        moneyAfterLabel.textColor=black;
        _periodLabel.textColor=black;
        _upDateLabel.textColor=black;
        isTodayLotteryLabel.textColor=redColor;
    }
}

@end
